package com.zzw.hj101;

import java.util.Scanner;

/**
 * @Project: hw_java
 * @Description: 输入整型数组和排序标识，对其元素按照升序或降序排序
 * @Author: zzw
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main2 {
    // 升序排序
    public static void ascSort(int[] num) {
        for (int i = 0; i < num.length - 1; i++) {
            for (int j = 0; j < num.length - i - 1; j++) {
                if (num[j] > num[j + 1]) {
                    int temp = num[j + 1];
                    num[j + 1] = num[j];
                    num[j] = temp;
                }
            }
        }
    }

    // 降序排序
    public static void descSort(int[] num) {
        for (int i = 0; i < num.length - 1; i++) {
            for (int j = 0; j < num.length - i - 1; j++) {
                if (num[j] < num[j + 1]) {
                    int temp = num[j + 1];
                    num[j + 1] = num[j];
                    num[j] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        int flag;
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        flag = in.nextInt();
        if (flag == 0) {
            ascSort(arr);
        }
        if (flag == 1) {
            descSort(arr);
        }
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }
}